package org.edu.modules.sxjy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Objects;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.sxjy.entity.VeCommon;
import org.edu.modules.sxjy.entity.VeDynamic;
import org.edu.modules.sxjy.service.IVeDynamicService;
import org.edu.modules.sxjy.utils.PageResponseResult;
import org.edu.modules.sxjy.vo.VeDynamicAddVo;
import org.edu.modules.sxjy.vo.VeDynamicVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"实习动态记录管理"})
@RestController
@RequestMapping({"/sxjy/veDynamic"})
@Component
@ApiSort(60)
public class VeDynamicController
        extends BaseController<VeDynamic, IVeDynamicService>
{
    private static final Logger log = LoggerFactory.getLogger(VeDynamicController.class);
    @Autowired
    private IVeDynamicService veDynamicService;

    @AutoLog("实习动态记录管理-查询列表")
    @ApiOperation(value="查询列表", notes="实习动态记录管理-查询列表")
    @GetMapping({"/selectAll"})
    public PageResponseResult selectAll(VeDynamicVo veDynamicVo, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, VeCommon veCommon)
    {
        Integer startLine = Integer.valueOf((pageNo.intValue() - 1) * pageSize.intValue());
        List<VeDynamicVo> veDynamicVoList = this.veDynamicService.selectAll(veDynamicVo, startLine, pageSize, veCommon);
        int total = this.veDynamicService.getSumPage(veDynamicVo, veCommon);
        if ((Objects.isNull(veDynamicVoList)) && (veDynamicVoList.size() <= 0)) {
            return new PageResponseResult(Integer.valueOf(1), 1, 0, Result.OK());
        }
        double totals = total;
        double pageSizes = pageSize.intValue();
        double totalPage = Math.ceil(totals / pageSizes);
        return new PageResponseResult(pageNo, (int)totalPage, total, Result.OK(veDynamicVoList));
    }

    @AutoLog("实习动态记录管理-查看详细信息")
    @ApiOperation(value="查看详细信息", notes="实习动态记录管理-查看详细信息")
    @GetMapping({"/selectOneInfo"})
    public Result<?> selectOneInfo(int id)
    {
        return this.veDynamicService.getOneInfo(id);
    }

    @AutoLog("实习动态记录管理-提交动态")
    @ApiOperation(value="提交动态", notes="实习动态记录管理-提交动态")
    @PostMapping({"/submitDynamic"})
    public Result<?> submitDynamic(@RequestBody VeDynamicAddVo veDynamicAddVo)
    {
        return this.veDynamicService.submitDynamic(veDynamicAddVo);
    }

    @AutoLog("实习动态记录管理-提交跟踪状态")
    @ApiOperation(value="提交跟踪状态", notes="实习动态记录管理-提交跟踪状态")
    @PutMapping({"/updateRemark"})
    public Result<?> updateRemark(VeDynamicVo veDynamicVo)
    {
        if (veDynamicVo != null)
        {
            this.veDynamicService.updateRemark(veDynamicVo);
            return Result.ok("提交成功");
        }
        return Result.error("提交失败");
    }

    @AutoLog("实习动态记录管理-根据id获取单条数据")
    @ApiOperation(value="根据id获取单条数据", notes="实习动态记录管理-根据id获取单条数据")
    @GetMapping({"/getOnes"})
    public Result<?> getOnes(int id)
    {
        VeDynamic veDynamic = (VeDynamic)this.veDynamicService.getById(Integer.valueOf(id));
        if (veDynamic == null) {
            return Result.error("暂时还没有安排实习！");
        }
        return Result.OK(veDynamic);
    }
}
